//三、红黑树查找结点
//----------------------------------------------------
//rb_search_auxiliary：查找
//rb_node_t* rb_search：返回找到的结点
//----------------------------------------------------
static rb_node_t* rb_search_auxiliary(key_t key, rb_node_t* root,
                                        rb_node_t** save)
{
    rb_node_t *node = root, *parent = NULL;
    int ret;

    /* 循环并不断判断走左或走右 */
    while (node) {
        parent = node;
        ret = node->key - key;
        if (0 < ret) {
            node = node->left;
        } else if (0 > ret) {
            node = node->right;
        } else {
            return node;
        }
    }
 
    if (save) {
        *save = parent;
    }
 
    return NULL;
}
 
//返回上述rb_search_auxiliary查找结果
rb_node_t* rb_search(key_t key, rb_node_t* root)
{
    return rb_search_auxiliary(key, root, NULL);
}